{extend name="public/base" /}
{block name="style"}
<link rel="stylesheet" href="__THEME__/default/view/admin/static/css/module.css?v={:time_version()}">
{/block}

{block name="content-header"}
<!-- Content Header (Page header) -->
<div class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1 class="m-0 text-dark">
					<h1>访问授权</h1>
				</h1>
			</div><!-- /.col -->
			<div class="col-sm-6">
				<ol class="breadcrumb float-sm-right">
					<li class="breadcrumb-item"><a href="{:Url('index/index')}">首页</a></li>
					<li class="breadcrumb-item"><a href="{:Url('authmanage/index')}">权限管理</a></li>
					<li class="breadcrumb-item active">访问授权</li>
				</ol>
			</div><!-- /.col -->
		</div><!-- /.row -->
	</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
{/block}

{block name="content-content"}
<!-- Main content -->
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">

				<div class="tab-wrap">
					<ul class="tab-nav nav">
						<li class="current"><a href="javascript:;">访问授权</a></li>
						<li><a href="{:Url('Authmanage/category',array('group_name'=>input('group_name') ,'group_id'=> input('group_id')))}">分类授权</a></li>
						<li><a href="{:Url('Authmanage/user',array('group_name'=>input('group_name') ,'group_id'=> input('group_id')))}">成员授权</a></li>
						<li class="fr">
							<select name="group">
								{volist name="auth_group" id="vo"}
								<option value="{:Url('Authmanage/access',array('group_id'=>$vo['id'],'group_name'=>$vo['title']))}" {eq name="vo['id']" value="$this_group['id']"}selected{/eq} >{$vo.title}</option>
								{/volist}
							</select>
						</li>
					</ul>
					<div class="tab-content">
						<!-- 访问授权 -->
						<div class="tab-pane in">
							<form action="{:Url('Authmanage/writeGroup')}" enctype="application/x-www-form-urlencoded" method="POST" class="form-horizontal auth-form">
								{volist name="node_list" id="node" }
								<dl class="checkmod">
									<dt class="hd">
									<label class="checkbox"><input class="auth_rules rules_all" type="checkbox" name="rules[]" value="<?php echo $main_rules[$node['url']] ?>">{$node.title}管理</label>
									</dt>
									<dd class="bd">
									{present name="node['child']"}
									{volist name="node['child']" id="child" }
									<div class="rule_check">
										<div>
											<label class="checkbox" {notempty name="child['tip']"}title='{$child.tip}'{/notempty}>
												<input class="auth_rules rules_row" type="checkbox" name="rules[]" value="<?php echo $auth_rules[$child['url']] ?>"/>{$child.title}
											</label>
										</div>
										{notempty name="child['operator']"}
										<span class="divsion">&nbsp;</span>
										<span class="child_row">
											{volist name="child['operator']" id="op"}
											<label class="checkbox" {notempty name="op['tip']"}title='{$op.tip}'{/notempty}>
												<input class="auth_rules" type="checkbox" name="rules[]"
													  value="<?php echo $auth_rules[$op['url']] ?>"/>{$op.title}
											</label>
											{/volist}
										</span>
										{/notempty}
									</div>
									{/volist}
									{/present}
									</dd>
								</dl>
								{/volist}

								<input type="hidden" name="id" value="{$this_group.id}" />
								<button type="submit" class="btn submit-btn ajax-post" target-form="auth-form">确 定</button>
								<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
							</form>
						</div>

						<!-- 成员授权 -->
						<div class="tab-pane"></div>

						<!-- 分类 -->
						<div class="tab-pane"></div>
					</div>
				</div>

			</div>
		</div>
	</div><!-- /.container-fluid -->
</section>
<!-- /.content -->

<!-- Main content -->
<!-- /.content -->
{/block}

{block name='script'}
<script type="text/javascript" src="/static/qtip/jquery.qtip.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/qtip/jquery.qtip.min.css" media="all">
<script src="__THEME__/default/view/admin/static/js/common.js?v={:time_version()}"></script>
<script type="text/javascript" charset="utf-8">
+function($){
	var rules = [{$this_group.rules}];
	$('.auth_rules').each(function(){
		if( $.inArray( parseInt(this.value,10),rules )>-1 ){
			$(this).prop('checked',true);
		}
		if(this.value==''){
			$(this).closest('span').remove();
		}
	});

	//全选节点
	$('.rules_all').on('change',function(){
		$(this).closest('dl').find('dd').find('input').prop('checked',this.checked);
	});
	$('.rules_row').on('change',function(){
		$(this).closest('.rule_check').find('.child_row').find('input').prop('checked',this.checked);
	});

	$('.checkbox').each(function(){
		$(this).qtip({
			content: {
				text: $(this).attr('title'),
				title: $(this).text()
			},
			position: {
				my: 'bottom center',
				at: 'top center',
				target: $(this)
			},
			style: {
				classes: 'qtip-dark',
				tip: {
					corner: true,
					mimic: false,
					width: 10,
					height: 10
				}
			}
		});
	});

	$('select[name=group]').change(function(){
		location.href = this.value;
	});
	//导航高亮
	highlight_subnav('{:Url('authmanager/index')}');
}(jQuery);
</script>
{/block}
